package com.quanxiaoha.weblog.web.controller.card;


import com.quanxiaoha.weblog.common.aspect.ApiOperationLog;
import com.quanxiaoha.weblog.common.domain.query.MemoryDataQuery;
import com.quanxiaoha.weblog.common.domain.query.SegmentQuery;
import com.quanxiaoha.weblog.common.domain.vo.*;
import com.quanxiaoha.weblog.common.service.IScheduleMemoryService;
import com.quanxiaoha.weblog.common.utils.Response;
import com.quanxiaoha.weblog.common.utils.TextSplitterUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author Roy
 * @since 2025-06-02
 */
@RestController
@RequestMapping("/todo")
@Slf4j
@Api(tags = "背记卡")
public class ScheduleMemoryController {

    @Autowired
    IScheduleMemoryService scheduleMemoryService;

    @GetMapping("/getMemoryData")
    @ApiOperationLog(description = "背记卡列表")
    @ApiOperation(value = "背记卡列表")
    public Response getMemoryData() {

        List<MemoryDataVo> memoryData = scheduleMemoryService.getMemoryData();
        return Response.success(memoryData);
    }

    @GetMapping("/getDocumentSegments")
    @ApiOperationLog(description = "获取列表")
    @ApiOperation(value = "获取列表")
    public Response getDocumentSegments(@RequestParam("title") String title) {

        List<SegmentVo> documentSegments = scheduleMemoryService.getDocumentSegments(title);
        return Response.success(documentSegments);
    }

    @PostMapping("/saveMemory")
    @ApiOperationLog(description = "保存背记卡")
    @ApiOperation(value = "保存背记卡")
    public Response saveMemory(@RequestBody SegmentQuery query) {

        scheduleMemoryService.saveMemory(query);
        return Response.success();
    }

    @PostMapping("/mergeMemory")
    @ApiOperationLog(description = "合并背记卡")
    @ApiOperation(value = "合并背记卡")
    public Response mergeMemory(@RequestBody MergeQuery query) {

        scheduleMemoryService.mergeMemory(query);
        return Response.success();
    }


    @GetMapping("/clockMemory/{id}")
    @ApiOperationLog(description = "打卡")
    @ApiOperation(value = "打卡")
    public Response clockMemory(@PathVariable Integer id) {

        ReadNumVo readNumVo = scheduleMemoryService.clock(id);
        return Response.success(readNumVo);
    }


    @PostMapping("/saveDocument")
    @ApiOperationLog(description = "解析文本")
    @ApiOperation(value = "解析文本")
    public Response saveDocument(@RequestBody MemoryDataQuery query) {

        scheduleMemoryService.saveDocument(query);
        return Response.success();
    }


    @DeleteMapping("/deleteMemory/{id}")
    @ApiOperationLog(description = "删除背记")
    @ApiOperation(value = "删除背记")
    public Response deleteMemory(@PathVariable Integer id) {

        scheduleMemoryService.deleteDocument(id);
        return Response.success();
    }

    @DeleteMapping("/deleteMemories/{title}")
    @ApiOperationLog(description = "删除文档")
    @ApiOperation(value = "删除文档")
    public Response deleteMemories(@PathVariable String title) {

        scheduleMemoryService.deleteMemories(title);
        return Response.success();
    }


}
